<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改党组织活动记录')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-activity-edit" th:object="${activity}">
            <input name="actId" th:field="*{actId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动组织机构：</label>
                <div class="col-sm-8">
                	<select id="org" class="form-control select2-multiple" th:field="*{orgId}" name="orgId">
						<option th:each="org:${orgs}" th:value="${org.orgId}"
							th:text="${org.orgName}"></option>
					</select>
                    <!-- <input name="orgId" th:field="*{orgId}" class="form-control" type="text" maxlength="10" required> -->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动类型：</label>
                <div class="col-sm-8">
                    <select name="orgType" class="form-control m-b" th:with="type=${@dict.getType('act_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{orgType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">活动主题：</label>
                <div class="col-sm-8">
                    <textarea name="actSubject" maxlength="100" class="form-control" required placeholder="请填写活动主题">[[*{actSubject}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动日期：</label>
                <div class="col-sm-8">
                        <!-- <input name="actDate" th:value="${#dates.format(activity.actDate, 'yyyyMMdd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" maxlength="8" required> -->
                     <input type="text" maxlength="10" name="actDate" th:field="*{actDate}" class="form-control time-input" required placeholder="yyyy-MM-dd">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动起止时间：</label>
                <div class="col-sm-8">
                    <input name="actDateRange" placeholder="格式为19:00:00-21:00:00" th:field="*{actDateRange}" class="form-control" type="text" maxlength="20" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动地点：</label>
                <div class="col-sm-8">
                    <input name="actAddr" th:field="*{actAddr}" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">非正式党员是否可以参加：</label>
                <div class="col-sm-8">
                    <select name="partyOnly" class="form-control m-b" th:with="type=${@dict.getType('party_only')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{partyOnly}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/activity";
        $("#form-activity-edit").validate({
            focusCleanup: true,
            rules:{
            	actDateRange:{
                    timeRange:true,
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-activity-edit').serialize());
            }
        }

        $(function(){
        	$('#org').select2({
                placeholder: "请选择活动组织机构",
                allowClear: true
            });
        	
        	
        	 jQuery.validator.addMethod("timeRange", function (value, element){
  		        return this.optional(element) || isTimeRange(value);
  		    },"请正确输入时间区间");
         	 
        	 function isTimeRange(time) {
         		console.log(time);
         		var pattern = /[0-2]\d:[0-5]\d:[0-5]\d-[0-2]\d:[0-5]\d:[0-5]\d/;
         		if(pattern.test(time)){
         			// 时间格式符合的情况下，验证前者时间小于后者时间
         			var arr = time.split("-");
         			var begin = arr[0];
         			var end = arr[1];
         			var begin_arr = begin.split(":");
         			var begin_hour = begin_arr[0];
         			var begin_minute = begin_arr[1];
         			var begin_second = begin_arr[2];
         			
         			var end_arr = end.split(":");
         			var end_hour = end_arr[0];
         			var end_minute = end_arr[1];
         			var end_second = end_arr[2];
         			if(parseInt(begin_hour)<=parseInt(end_hour)){
         				if(parseInt(begin_hour)==parseInt(end_hour)){
         					// 小时相等的情况下才需要比较分钟
         					if(parseInt(begin_minute)<=parseInt(end_minute)){
         						if(parseInt(begin_minute)==parseInt(end_minute)){
         							// 分钟相等的情况下才需要比较秒
         							if(parseInt(begin_second)<parseInt(end_second)){
                 						return true;
                 					}else{
                 						return false;// 秒验证失败
                 					}
         						}else{
         							return true;
         						}
             				}else{
             					return false;// 分钟验证失败
             				}
         				}else{
         					return true;
         				}
         			}else{
 						return false;// 小时验证失败        				
         			}
         		}else{
         			return false; // 时间格式已经不匹配
         		}
                 
              }
        	
        });
        
    </script>
</body>
</html>